<?php
/**
 * Created by PhpStorm.
 * User: a
 * Date: 2016/6/3
 * Time: 10:04
 */
require_once "file_zip.php";
/**
 * 中文字符，并填充空格
 */
function report_switch($name,$num){
    $name=iconv("UTF-8","gbk//TRANSLIT",$name);
    $name=$name=str_pad($name,$num," ",STR_PAD_RIGHT);
    return $name;
}

/**
 * 报文，地址拼接,并填充空格
 * @param $province
 * @param $city
 * @param $district
 * @param $address
 */
function report_address($province,$city,$district,$address,$num){
    $province_array=C("province_array");
    $count=count($province_array);
    $flag=false;
    for($i=0;$i<$count;$i++){
        if($province==$province_array[$count]){
            $flag=true;
            break;
        }
    }
    $add="";
    if($flag){
        $add=$province.$district.$address;
    }else{
        $add=$province.$city.$district.$address;
    }
    return report_switch($add,$num);
}

function random($len) {
    $srcstr = "1a2s3d4f5g6hj8k9qwertyupzxcvbnm";
    mt_srand();
    $strs = "";
    for ($i = 0; $i < $len; $i++) {
        $strs .= $srcstr[mt_rand(0, 30)];
    }
    return $strs;
}

function differ_month($start_time,$end_time){
    $start_year=date("Y",$start_time);
    $start_month=date("m",$start_time);
    $end_year=date("Y",$end_time);
    $end_month=date("m",$end_time);
    $deffer_month=($end_year-$start_year)*12+($end_month-$start_month);
    return $deffer_month;
}

function first_day_month($begin_time,$i){
    return strtotime("+$i month",strtotime(date("Y-m-01",$begin_time)));
}

function final_day_month($begin_time,$i){
    $i++;
    return strtotime("+$i month",strtotime(date("Y-m-01",$begin_time)))-1;
}

function array_remove(&$arr, $offset){
    array_splice($arr, $offset, 1);
}

/**
 * 安融分期订单接口
 * @param $url
 * @param $ref_url
 * @param $data
 * @param $login
 * @param $proxy
 * @param $proxystatus
 * @return mixed
 */
function curl_grab_page($url,$ref_url,$data,$login,$proxy,$proxystatus){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    if ($proxystatus == 'true') {
        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
        curl_setopt($ch, CURLOPT_PROXY, $proxy);
    }
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $ref_url);

    curl_setopt($ch, CURLOPT_TIMEOUT, 20);

    curl_setopt($ch, CURLOPT_HEADER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    ob_start();
    return curl_exec ($ch); // execute the curl command
    ob_end_clean();
    curl_close ($ch);
    unset($ch);
}

/**
 * 安融身份验证，银行卡，还款能力接口
 * @param $url
 * @return mixed
 */
function curl_page_exec($url){
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    ob_start();

    $file_contents = curl_exec($ch);
    return $file_contents;
    ob_end_clean();
    curl_close($ch);

}

function math_date($time,$end_time){
    $day=date("d",$time);
    $time2=strtotime(date("Y-m",time())."-".$day);
    if($time2>$end_time){
        return $end_time;
    }else{
        return $time2;
    }
}